import request from '@/utils/request'

/**
 *
 * @param {Sting} mobile 手机号
 * @param {Sting} code 密码
 * @returns Promise
 */

export const loginAPI = (mobile, code) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

/**
 *
 * @param {String} mobile
 * @returns Promise
 */
export const getCodeAPI = (mobile) => {
  return request({
    url: `/v1_0/sms/codes/${mobile}`
  })
}

// 获取用户信息
export const getUserInfoAPI = () =>
  request({
    // 要求请求头参数，携带token过去
    url: '/v1_0/user'
    // 携带的参数封装在request
  })
/**
 *  获取用户个人资料
 * @returns Promise
 */
export const getUserProfileAPI = () =>
  request({
    url: '/v1_0/user/profile'
  })

/**
 *  修改用户信息  修改那个传那个
 * @param {*} data {name , gender , birthday....}
 * @returns promise
 */
export const editUserProfileAPI = (data) =>
  request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
/**
 * 关注用户
 * @param {*} target 关注用户id
 * @returns promise
 */
export const followedAPI = (target) =>
  request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
/**
 * 取消关注
 * @param {*} target
 * @returns promise
 */
export const noFollowAPI = (target) =>
  request({
    url: `/v1_0/user/followings/${target}`,
    method: 'DELETE'
  })

export const uploadPhoto = (file) => {
  const fm = new FormData()
  fm.append('photo', file)
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data: fm
  })
}
